package preprocess;

import java.util.*;

import FlowGraph.*;
import SymbolTable.*;
import FlowGraph.Nodes.*;
import util.Util;
import util.InfoCollector;
import db.ClassData;

//////////////////////////////////////////////////////////////////////////
//// CSPInfoCollector
/**
@author Ivan Jeukens
@version v 0.1 18/10/2002
*/
public class CSPInfoCollector implements InfoCollector {

    public CSPInfoCollector() {
        _cspMethod = new LinkedList();
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void visitFGNode(FlowGraphNode node) {
        if(node.getType() != FlowGraphNode.METHOD_CALL) return;
        MethodCallNode mc = (MethodCallNode) node;

        String mname = mc.getMethodName();
        Class c = mc.getCallerType();
        if(mname != null && c != null && _isCSPMethod(mname) &&
               Util.isSubClass(c, ptolemy.domains.csp.kernel.CSPActor.class)) {
            _cspMethod.add(node);
        }
    }

    public void visitSTEntry(STEntry entryj, FlowGraphNode owner, ClassData info) {
    }

    public int cspMethodSize() {
        return _cspMethod.size();
    }

    public Iterator methodIterator() {
        return _cspMethod.iterator();
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private boolean _isCSPMethod(String name) {
        if(name.equals("chooseBranch") ||
           name.equals("delay") ||
           name.equals("getConditionalBranchController")) {
            return true;
        }
        
        return false;
    }

    ///////////////////////////////////////////////////////////////////
    ////                       private variables                   ////

    private LinkedList _cspMethod;
}
